<?php // no direct access
defined('_JEXEC') or die('Restricted access');
/**
 * Category menu module
 *
 * @package VirtueMart
 * @subpackage Modules
 * @copyright Copyright (C) OpenGlobal E-commerce. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL V3, see LICENSE.php
 * @author OpenGlobal E-commerce
 *
 */
if (!class_exists( 'VirtueMartModelCategory' )) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'category.php');
$categoryModel = VmModel::getModel('Category');
$vendorId = '1';

//print_r($_GET);exit;
$html = '';
$db = JFactory::getDBO();
$query = 'SELECT virtuemart_category_id, category_name FROM #__virtuemart_categories_vi_vn c INNER JOIN #__virtuemart_category_categories cc ON c.virtuemart_category_id = cc.category_child_id WHERE cc.category_parent_id = 0';
$db->setQuery($query);
$head_cats = $db->loadObjectList();
$i = 1;
foreach($head_cats as $head_cat){?>
    <p class="title"><?php echo $head_cat->category_name;?></p>
    <?php
    $categories = $categoryModel->getChildCategoryList($vendorId, $head_cat->virtuemart_category_id);
    if($categories){
        $html .= '<div class="sidenav'.$i.'"><ul>';
        foreach($categories as $cat){
            if($cat->virtuemart_category_id == JRequest::getVar('virtuemart_category_id')){
                $current = 'active';
            } else {
                $current = '';
            }
            $caturl = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$cat->virtuemart_category_id);
            $html .= '<li id="item'.$cat->virtuemart_category_id.'" class="top '.$current.'"><a href="'.$caturl.'">'.$cat->category_name;
            $categories1 = $categoryModel->getChildCategoryList($vendorId, $cat->virtuemart_category_id);
            if($categories1){
                $html .= '<ul>';
                foreach($categories1 as $cat1){
                    if($cat1->virtuemart_category_id == JRequest::getVar('virtuemart_category_id')){
                        $current1 = 'class="active"';
                        $active = $cat->virtuemart_category_id;
                    } else {
                        $current1 = '';
                    }
                    $caturl1 = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$cat1->virtuemart_category_id);
                    $html .= '<li '.$current1.'><a href="'.$caturl1.'">'.$cat1->category_name;
					$categories2 = $categoryModel->getChildCategoryList($vendorId, $cat1->virtuemart_category_id);
					if($categories2){
						$html .= '<ul>';
						foreach($categories2 as $cat2){
							if($cat2->virtuemart_category_id == JRequest::getVar('virtuemart_category_id')){
								$current2 = 'class="active"';
								$active = $cat1->virtuemart_category_id;
							} else {
								$current2 = '';
							}
							$caturl2 = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$cat2->virtuemart_category_id);
							$html .= '<li '.$current2.'><a href="'.$caturl2.'">'.$cat2->category_name.'</a></li>';
						}
						$html .= '</ul>';
					}
					$html .= '</a></li>';
                }
                $html .= '</ul>';
            }
            $html .= '</a></li>';
        }
        $html .= '</ul></div>';
		echo $html;
    }
	$html = '';
    $i++;
}?>
<?php if($active){?>
<script language="javascript">
jQuery(document).ready( function(){
    activeLi = function(id){
        jQuery("#item"+id).addClass('active');
        jQuery("#item"+id+" .list_bloclSP_sub").slideDown('normal');
    }
    
    activeLi(<?php echo $active;?>);
});
</script>
<?php }?>